const app = getApp();
var Mcaptcha = require('../../utils/mcaptcha.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Uname: '18533346223',
    Upwd: 'aa123456789',
    Tel: '',
    LY: '小程序',
    txt: '',
    ckmmt: true,
    isShow: false,
    ckmm: 'icon-yanjing',
    inputYzm: '',
    inputPyzm: '',
    iscode: '',
    disabled: true,
    num: '',
    codename: '获取验证码'
  },
  inputTel: function (e) {
    this.setData({
      Tel: e.detail.value
    })
  },
  inputPass: function (e) {
    this.setData({
      Upwd: e.detail.value
    })
  },
  inputYzm: function (e) {
    this.setData({
      inputYzm: e.detail.value
    })
  },
  inputPyzm: function (e) {
    this.setData({
      inputPyzm: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  getRanNum: function () {
    var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
    var pwd = '';
    for (var i = 0; i < 4; i++) {
      if (Math.random() < 48) {
        pwd += chars.charAt(Math.random() * 48 - 1);
      }
    }
    return pwd;
  },

  /**sn.toUpperCase()
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.changePyzm();
  },

  changePyzm: function () {
    var that = this;
    var num = that.getRanNum();
    // console.log(num)
    this.setData({
      num: num
    })
    new Mcaptcha({
      el: 'canvas',
      width: 80,//对图形的宽高进行控制
      height: 30,
      code: num
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  loginckmm: function () {
    if (this.data.ckmmt) {
      this.setData({
        ckmmt: false,
        ckmm: 'icon-yanjing1'
      })
    } else {
      this.setData({
        ckmmt: true,
        ckmm: 'icon-yanjing'
      })
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  logingetyzm: function () {
    this.getCode();
  },
  logingetyzmN: function () {
    // body...
  },
  getCode: function () {
    var that = this;
    var tel = this.data.Tel;
    var myreg = /^(14[0-9]|16[0-9]|19[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$$/;
    if (!myreg.test(tel)) {
      app.tishi('请输入正确的手机号');
      return false;
    } else if (this.data.inputPyzm.toUpperCase() != this.data.num.toUpperCase()) {
      app.tishi('请输入正确的图形验证码');
      return false;
    } else {
      var api_input = {
        tel: this.data.Tel
      }
      app.getDaoPost('api/FeijiuApp/Feijiu_GetTelYzm_FindPwd', api_input, function (r) {
        if (r.code == 200) {
          app.tishi(r.data.Mess);

          that.setData({
            iscode: app.aesDec(r.data.Yzm),
            disabled: false
          })
          var num = 61;
          var timer = setInterval(function () {
            num--;
            if (num <= 0) {
              clearInterval(timer);
              that.setData({
                codename: '重新发送',
                disabled: true,
              })
            } else {
              that.setData({
                codename: num + "s后重新获取"
              })
            }
          }, 1000)
        } else {
          app.tishi(r.message)
        }
      })
    }
  },
  loginBtn: function () {
    // var that = this;
    // var upwdgz = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,14}$/;
    // var uTel = /^(14[0-9]|16[0-9]|19[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$$/;
    // if (!uTel.test(this.data.Tel)) {
    //    app.tishi('请输入正确的手机号');
    //    return false
    // }else if (!upwdgz.test(this.data.Upwd)) {
    //    app.tishi('请输入6-14个字符的密码');
    //    return false       
    // }else if (this.data.inputPyzm.toUpperCase() != this.data.num.toUpperCase()) {
    //  app.tishi('请输入正确的图形验证码');
    //  return false;  
    // }else if (this.data.inputYzm != this.data.iscode || this.data.inputYzm.length < 6 ) {
    //  app.tishi('请输入正确手机验证码');
    //  return false;  
    // }else{

    // var ss = {strKey:'U2FsdGVX8mLqSLnHYjvqkX1MLHBt41W8tVTY1L'}
    // app.getDaoPostOld('api/FeijiuApp/PostReqTKInfo',ss,function (r) {
    //   console.log(r)
    // })
    // var api_input = {
    //   Tel:this.data.Tel,
    //   NewPassword:app.aesAdd(this.data.Upwd),
    //   strRSA:'87f291f8-da76-4c33-9002-f7f5aeddfa39'
    // }
    // app.getDaoPost('api/FeijiuApp/PostPasswordByTelLogin140',api_input,function (r) {
    //   console.log(r)
    // })

    // }




  },

})